<?php

namespace app\staff\controller;

use app\common\controller\StaffBase;
use think\Db;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Region extends StaffBase
{
    
    /**
     * Seniors模型对象
     * @var \app\admin\model\Seniors
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();

    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

    /*
    *选择城市，城市联动
     */
    public function select($value='')
    {
        $type = $this->request->get('type');
        $group_id = $this->request->get('group_id');
        $list = null;
        if ($group_id !== '') {
            if ($type == 'province') {
                $list = db('region')->field('id as value, name')->where(['level'=>1,'pid'=>0])->select();
            } else {
                $list = db('region')->field('id as value, name')->where(['pid'=>$group_id])->select();
            }
        }
        $this->success('', null, $list);
    }

    /*
    *选择城市，城市联动
     */
    public function area($value='')
    {
        $province = $this->request->get('province');
        $city = $this->request->get('city');

        $where = [];

        $where['pid'] = 0;
        if ( $province ) {
            $where['pid'] = $province;
        }
        if ( $city ) {
            $where['pid'] = $city;
        }
        $list = db('region')->field('id as value, name')->where($where)->select();
        $this->success('', null, $list);
    }
       
}
